#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include"hub.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    Hub* pHub=new Hub;
    engine.rootContext()->setContextProperty("pHub",pHub);
    engine.addImageProvider("live",pHub->m_pImageViewer->m_pImageProvider);
    engine.addImageProvider("result",pHub->m_pImageProcess->m_pImageProvider);
    engine.rootContext()->setContextProperty("pImageViewer",pHub->m_pImageViewer);
    //engine.rootContext()->setContextProperty("pImageProcess",pHub->m_pImageProcess);

    const QUrl url(u"qrc:/CameraOpenCV/main.qml"_qs);
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    qDebug() << "Main thread : " << QThread::currentThreadId();

    return app.exec();
}
